<?php
// +----------------------------------------------------------------------
// | Action ：门票模块
// +----------------------------------------------------------------------
// | DateTime：2015年12月9日
// +----------------------------------------------------------------------
// | Author: Danson <zoudan916@163.com>
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Admin\TicketsModel;

class TicketsController extends AdminController{

    /* 门票列表 */
    public function index(){
        $list = $this->lists('tickets');
        $this->assign('list',$list);
        $this->display();
    }

    /* 更新门票 */
    public function save(){
        $Tickets = D('Tickets');
        if(IS_POST){
            $id = I('post.tickets_id', 0, 'intval');
            $data['tickets_id'] = I('post.tickets_id','','intval');
            $data['tickets_name'] = I('post.tickets_name','','trim');
            $data['tickets_num'] = I('post.tickets_num',0,'intval');
            $data['tickets_price'] = I('post.tickets_price',0,'float');
            $data['vip_price'] = I('post.vip_price',0,'float');
            $data['projects'] = I('post.projects','','trim');
            if($Tickets->create($data)){
                $result = $id ? $Tickets->save() : $Tickets->add();
                if($result){
                    $this->success('更新成功',U('index'));
                }else{
                    $this->error('更新失败');
                }
            }else{
                $this->error($Tickets->getError());
            }
        }
        $id = I('get.id',0,'intval');
        $info = $Tickets->where(array('tickets_id'=>$id))->find();
        $this->assign('info',$info);
        $this->display();
    }

    /* 删除 */
    public function del(){

    }

    /* 门票订单 */
    public function order(){
        if(isset($_GET[''])){

        }
        $list = $this->lists('order',array('status'=>20));
        $this->assign('list',$list);
        $this->display();
    }

    /* 审核 */
    public function check(){
        $id = I('get.id',0,'intval');
        $info = M('order')->where(array('order_id'=>$id))->find();
        if(M('order')->where(array('order_id'=>$id))->save(array('check'=>1))){
            send_sms($info['user_phone'],'尊敬的'.$info['user_name'].'，您购买的重庆首届社群群主大会通票已成功兑票，祝您与会愉快！');
            $this->success('审核成功',U('order'));
        }else{
            $this->error('审核失败');
        }

    }
}